import * as THREE from 'three';

// 是否为全屏
export function isFull() {
  return window.screen.height === window.innerHeight;
}

// 浏览器打开全屏
export function requestFullScreen(element) {
  var requestMethod =
    element.requestFullScreen ||
    element.webkitRequestFullScreen ||
    element.mozRequestFullScreen ||
    element.msRequestFullScreen;

  return requestMethod && requestMethod.call(element);
}

// 浏览器退出全屏
export function exitFullScreen() {
  var exitMethod =
    document.exitFullscreen ||
    document.mozCancelFullScreen ||
    document.webkitExitFullscreen ||
    document.webkitExitFullscreen;
  return exitMethod && exitMethod.call(document);
}

export function createObject(name, position) {
  var geometry = new THREE.BoxGeometry(0.001, 0.001, 0.001); // 创建一个立方体几何对象Geometry
  var material = new THREE.MeshLambertMaterial({ color: 0xffffff, opacity: 0, transparent: true });
  var mesh = new THREE.Mesh(geometry, material); // 网格模型对象Mesh
  mesh.name = name;
  mesh.userData = { name };
  mesh.position.set(...position);
  return mesh;
}

// 节流函数
export function throttle(func, delay) {
  let previous = Date.now();

  return function () {
    const params = [...arguments];
    const context = this;
    const timestamp = Date.now();
    if (timestamp - previous > delay) {
      func.apply(context, params);
      previous = timestamp;
    }
  };
}
